<template>
	<view :class="Visible ? 'usable-coupon open' : 'usable-coupon close'">
		<view class="popup-bg" @click="closePopup"></view>
		<view style="border-top-right-radius: 20rpx;border-top-left-radius: 20rpx;" class="main pt30" v-on:click.stop>
            <view class="distr-tit">我的权益卡</view>
			<view class="distr-des">请选择用于抵扣的权益卡</view>
			<view class="p-0-30" style="padding-bottom: 50rpx">
				<u-radio-group v-model="value" active-color="#f53630">
				<view v-for="(item, index) in datalist">
					<view class="fsc" style="padding: 10rpx;margin-bottom:40rpx;">
						<view class="benefit-card">
							<image class="addree_icon" :src="item.image.file_path" mode=""></image>
							<view class="info">
								<view>{{item.product_name}}</view>
								<view class="benefit-str">
									<block v-for="(it, itIndex) in item.OrderBenefit">
										<text>{{it.benefit_name}}:{{it.surplus_number}}</text>
									</block>
								</view>
							</view>
						</view>
						<view style="display: flex;color: #F63E36" @click="chooseItem(item)">
							<u-radio @change="radioChange" :name="item.order_product_id" >
							</u-radio>
						</view>
					</view>
				</view>
					<view class="fsc" style="padding: 10rpx">
						<view>不使用权益卡</view>
						<view>
							<u-radio @change="radioChange" :name="0" >
							</u-radio>
						</view>
					</view>
				</u-radio-group>
			</view>

            <view class="distr_btn">
                <button class="btn-gcred" @click="submit">确认</button>
            </view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				/*手机高度*/
				phoneHeight: 0,
				/*可滚动视图区域高度*/
				scrollviewHigh: 0,
				/*是否可见*/
				Visible: false,
				/*优惠券列表*/
				datalist: {},
				/*尺寸比例*/
				ratio: 1,
                value: 0,
				choose: {}
			};
		},
		props: ['isBenefit', 'benefitList','benefit_id'],

		onLoad() {},
		mounted() {
			this.init();
		},
		watch: {
			isBenefit: function(n, o) {
				if (n != o) {
					this.Visible = n;
					this.datalist = this.benefitList;
					this.getHeight();
				}
			}
		},
		methods: {
			/*初始化*/
			init() {
				let self = this;
				self.value = self.benefit_id
				uni.getSystemInfo({
					success(res) {
						self.phoneHeight = res.windowHeight;
						self.ratio = res.windowWidth / 750;
						self.getHeight();
					}
				});
			},
            radioChange(e) {
            },
			
			chooseItem(item) {
				this.choose = item;
				console.log(123123)
				console.log(this.choose)
			},

			/*获取高度*/
			getHeight() {
				let count = Object.keys(this.benefitList).length;
				if (count > 2) {
					this.scrollviewHigh = this.phoneHeight * 0.6;
				} else {
					if (count == 1) {
						this.scrollviewHigh = 230 * this.ratio;
					} else if (count == 2) {
						this.scrollviewHigh = 460 * this.ratio;
					}
				}
			},
            submit() {
                let self = this;
				console.log(11111)
				console.log(self.value)
                if (self.value==0) {
                    self.closePopup(0)
                } else {
                    self.selectCoupon(self.value)
                }

            },

			/*选择优惠券*/
			selectCoupon(e) {
				this.closePopup(e);
			},
			/*关闭弹窗*/
			closePopup(e) {
				this.$emit('close', e, this.choose);
			}
		}
	};
</script>

<style lang="scss">
    .distr_btn button {
        width: 90%;
        margin: 0 auto;
        margin-bottom: 30rpx;
        height: 60rpx;
        line-height: 60rpx;
        border-radius: 30rpx;
    }
    .distr-tit {
        text-align: center;
        font-size: 32rpx;
        margin-bottom: 10rpx;
    }
	.distr-des {
		text-align: center;
		font-size: 24rpx;
		margin-bottom: 48rpx;
		color: #999999;
	}
	.usable-coupon .popup-bg {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 99;
	}

	.usable-coupon .main {
		position: fixed;
		width: 100%;
		bottom: 0;
		min-height: 200rpx;
		max-height: 900rpx;
		background-color: #fff;
		transform: translate3d(0, 980rpx, 0);
		transition: transform 0.2s cubic-bezier(0, 0, 0.25, 1);
		bottom: env(safe-area-inset-bottom);
		z-index: 99;
	}

	.usable-coupon .main {
		position: fixed;
		width: 100%;
		bottom: 0;
		min-height: 200rpx;
		max-height: 900rpx;
		background-color: #fff;
		transform: translate3d(0, 980rpx, 0);
		transition: transform 0.2s cubic-bezier(0, 0, 0.25, 1);
		bottom: env(safe-area-inset-bottom);
		z-index: 99;
	}

	.usable-coupon.open .main {
		transform: translate3d(0, 0, 0);
	}

	.usable-coupon.close .popup-bg {
		display: none;
	}

	.b-radio {
		border: 1rpx solid #FFFFFF;
		border-radius: 30rpx;
		padding: 10rpx 30rpx;
	}
	
	.benefit-card {
		display: flex;
		width: 85%;
		image {
			width: 160rpx;
			height: 90rpx;
			margin-right: 16rpx;
			border-radius: 8rpx
		}
		.benefit-str {
			color: #999999;
			font-size: 24rpx;
			text {
				margin-right: 20rpx;
			}
		}
		.info {
			width: 70%;
		}
	}
</style>
